package com.zeltov.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.zeltov.api.CarServiceBasic;
import com.zeltov.api.CarTO;
import com.zeltov.api.DriverDTO;

public class HelloWorldExample extends HttpServlet {

	private static final long serialVersionUID = -7287054730111138812L;

	static Log log = LogFactory.getLog(HelloWorldExample.class);
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    {
		log.debug("HelloWorldExample");
		
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        CarTO carDTO = new CarTO();
        carDTO.setId(1);
        carDTO.setName("car");
        
        DriverDTO driverDTO = new DriverDTO();
        driverDTO.setId(0);
        driverDTO.setName("driver");
        
		List<CarTO> allCarEOs = new CarServiceBasic().getAllCars();

		for (CarTO car: allCarEOs) {
			log.debug( ToStringBuilder.reflectionToString(car,
					ToStringStyle.SHORT_PREFIX_STYLE));
			
		}
		/**/
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Hello Alex World!</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Hello " +  carDTO.getId() + " - " + carDTO.getName() +"  World!</h1>");
        out.println("<h1>Hello " +  driverDTO.getId() + " - " + driverDTO.getName() +"  World!</h1>");
        out.println("</body>");
        out.println("</html>");
    }
}
